import pymongo

# 创建客户端连接
client = pymongo.MongoClient('localhost', 27017)

# 基于客户端创建数据库
db = client['spider-db']

# 基于数据库，创建数据表
collection = db['movie']

# 基于数据表做数据的增删改查
# 新增一条数据
# collection.insert_one({
#     "name": '来福大饭店',
#     "grade": 9.9,
#     "actors": "黄轩",
#     "duration": 160
# })
# 新增多条数据
collection.insert_many([
    {
        "name": '来福大饭店1',
        "grade": 9.8,
        "actors": "黄轩",
        "duration": 160
    },
    {
        "name": '来福大饭店2',
        "grade": 9.5,
        "actors": "黄轩",
        "duration": 160
    },
    {
        "name": '来福大饭店3',
        "grade": 9.3,
        "actors": "黄轩",
        "duration": 160
    }
])

